<?php
error_reporting(0);
include_once "../controle/db.php";
include_once "../controle/valida.php";
include_once "config.php";
$chave = "rtg4df65g4t";
$security_key = md5(date("YmdHm").$chave);


if($_GET["s"] == $security_key){
    
    if($_GET["a"] != '' && valida::numero($_GET["a"])){
        
        // apaga o arquivo de backup
        shell_exec("rm -f tmp/".$_GET["a"].".tar.gz");
        
    }else{
        
        // cria pasta temporária
        $temp_dir = date("YmdHis");
        shell_exec("mkdir tmp/".$temp_dir);

        // cria diretorio de backup
        include_once "bkp_sql.php";
        include_once "bkp_arquivo.php";

        // compacta diretorio de bacup
        shell_exec("cd tmp; tar -czf $temp_dir.tar.gz $temp_dir; rm -fr $temp_dir; cd ..");

        echo $temp_dir;
        
    }
    
}